package com.wk.springboot;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;
import java.util.UUID;

public class XSSFExcelTest {

    public static void main(String[] args) throws IOException, InterruptedException {
//创建一个新的工作簿
        XSSFWorkbook workbook = new XSSFWorkbook();
//
        // 创建一个新的表格
        Sheet sheet = workbook.createSheet("Example Sheet");
        for (int i = 0; i < 10000; i++) {
            //创建行（从0开始计数）
            Row row = sheet.createRow(i);
            for (int j = 0; j < 100; j++) {
            //在行中创建单元格（从0开始计数）
                Cell cell = row.createCell(j);
            //设置单元格的值
                cell.setCellValue(UUID.randomUUID().toString());
            }
        }
        //设置文件路径和名称
        String filename = "./example.xlsx";

        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        System.out.println("开始写文件："+s);
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(filename);
            workbook.write(fileOutputStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            workbook.close();
        }

    }

}
